package com.dong.dao.impl;

import com.dong.dao.BaseDao;
import com.dong.dao.ClassDao;
import com.dong.entity.Class;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaoDong
 * @version 1.0.0
 * @ClassName ClassDaoImpl.java
 * @Description TODO
 * @createTime 2024年05月06日 16:29:00
 */
public class ClassDaoImpl extends BaseDao implements ClassDao {
    @Override
    public List<Class> selectAll() {
        String sql = "SELECT * FROM `class`";
        ResultSet resultSet = executeQuery(sql);
        List<Class> classList = new ArrayList<>();
        if (resultSet != null) {
            try {
                while (resultSet.next()) {
                    Class cc = new Class();
                    cc.setId(resultSet.getInt("id"));
                    cc.setClassName(resultSet.getString("className"));
                    classList.add(cc);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                closedAll(resultSet);
            }
        }


        return classList;
    }
}
